<script setup lang='ts' name="video-management-detail">
import { getVideoDetail } from '@fl/api/fangjiaohui'
import UpdatedOss from '@fl/components/upLoad-oss.vue'
import { ElDialog, ElForm, ElFormItem } from 'element-plus'
import { nextTick, toRefs } from 'vue'

const props = withDefaults(defineProps<{
    data?: any
    modelValue: boolean
    videoType: any
}>(), {
    data: () => {},
})

const emits = defineEmits(['update:modelValue', 'confirm'])
const { data, modelValue } = toRefs(props)

const state = { catId: '', img: '', info: '', title: '', url: '' }
const form = ref<any>({ ...state })

const formRef = ref()

function close() {
    emits('update:modelValue', false)
}

async function init(val: any) {
    await nextTick()
    getVideoDetail(val.id).then((res: any) => {
        form.value = res.data
    })
}

watch(data, (val: any) => {
    if (val)
        init(val)
}, {
    deep: true,
    immediate: true,
})
</script>

<template>
    <ElDialog v-model="modelValue"
              width="600"
              title="详情"
              @close="close"
    >
        <ElForm ref="formRef"
                :model="form"
                label-width="auto"
                style="max-width: 500px"
        >
            <ElFormItem label="视频分类:">
                {{ form.catName }}
            </ElFormItem>

            <ElFormItem label="视频标题:"
                        prop="title"
            >
                {{ form.title }}
            </ElFormItem>

            <ElFormItem label="视频说明:"
                        prop="info"
            >
                {{ form.info }}
            </ElFormItem>

            <ElFormItem label="视频上传:"
                        prop="url"
            >
                <UpdatedOss v-model="form.url"
                            :is-video="true"
                            :disabled="true"
                />
            </ElFormItem>

            <ElRow>
                <ElCol :span="12">
                    <ElFormItem label="视频封面:">
                        <UpdatedOss v-model="form.img"
                                    :disabled="true"
                        />
                    </ElFormItem>
                </ElCol>
            </ElRow>
        </ElForm>
    </ElDialog>
</template>
